temp1=zeros(n_data,1);
temp2=zeros(n_data,1);
tempC=zeros(n_data,1);

for i= 1:1:n_data
    temp2(i,1) = X'*K(:,:,i)'*K(:,:,i)*X;
    temp1(i,1) = tau(:,i)'*K(:,:,i)*X;
    tempC(i,1) = tau(:,i)'* tau(:,i);
end

re_temp2_sum = X'*G'*G*X;
re_temp1_sum=b'*G*X;
re_tempC_sum = b'*b;
(sum(temp2-2*temp1+tempC)-((G*X+b)'*(G*X+b) -b'*b + sum(tempC)) )

sum(temp2)- re_temp2_sum
-sum(temp1)- re_temp1_sum
%     second_order_err = K_sum - G'*G
%     first_order_err = BK_sum - b'*G